Volumetric = cc.Node.extend({

	ctor:function(parent,tag){
		this._super();
		this.init();
		parent.addChild(this,9,TAG_VOLUMETRIC_NODE);
	
	},
	init:function(){
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.body=new Button(this,10,TAG_VOLUMETRIC,"#volumetric.png",this.callback);
		var lid6=new Button(this,11,TAG_LID6,"#lid6.png",this.callback);

		//lid6.setScale(0.5, 0.5);
		lid6.setPosition(cc.p(2, this.body.height*0.45));
	},
	openLib:function(){
		var ber = cc.bezierBy(1.5,[cc.p(50,90),cc.p(60,-140),cc.p(60,-145)]);
		var rotate = cc.rotateTo(1.5, 90);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,cc.callFunc(function() {
			this.getChildByTag(TAG_LID6).setRotation(90);
			//this.getChildByTag(TAG_LID6).setSpriteFrame("lid7.png");
			gg.flow.next();
		},this));
		this.getChildByTag(TAG_LID6).runAction(seq);
	},
	openLib1:function(){
		var ber = cc.bezierBy(1.5,[cc.p(50,90),cc.p(60,-140),cc.p(60,-145)]);
		var rotate = cc.rotateTo(1.5, 90);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,cc.callFunc(function() {
			this.getChildByTag(TAG_LID6).setRotation(90);
			//this.getChildByTag(TAG_LID6).setSpriteFrame("lid7.png");
			this.getChildByTag(TAG_LID6).runAction(cc.fadeOut(0.5));
			gg.flow.next();
		},this));
		this.getChildByTag(TAG_LID6).runAction(seq);
	},
	closeLib:function(){
		var ber = cc.bezierBy(1.5,[cc.p(-10,75),cc.p(-60,210),cc.p(-60,140)]);
		var rotate = cc.rotateTo(1.5, 0);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,cc.callFunc(function() {
			this.getChildByTag(TAG_LID6).setRotation(0);
			this.getChildByTag(TAG_LID6).setSpriteFrame("lid6.png");
			gg.flow.next();
		},this));
		this.getChildByTag(TAG_LID6).runAction(seq);
	},
	closeLib1:function(){
		var ber = cc.bezierBy(1.5,[cc.p(-10,75),cc.p(-60,210),cc.p(-60,150)]);
		var rotate = cc.rotateTo(1.5, 0);
		var spawn = cc.spawn(ber, rotate);
		var seq = cc.sequence(spawn,cc.callFunc(function() {
			this.getChildByTag(TAG_LID6).setRotation(0);
			this.getChildByTag(TAG_LID6).setSpriteFrame("lid6.png");
			gg.flow.next();
		},this));
		this.getChildByTag(TAG_LID6).runAction(seq);
	},
	callback:function(p){
		var hand=new Hand();
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);
		func.retain();
		switch(p.getTag()){
		case TAG_LID6:
			var action=gg.flow.flow.action;
			if(action==K6)
				{
			this.openLib();
				}
			if(action==K7)
			{
				this.openLib1();
				
				
			}
			else if(action==K2)
				this.closeLib();
			else if(action==K3)
				this.closeLib1();
			break;
		case  TAG_VOLUMETRIC:
			var lid66=this.getChildByTag(TAG_LID6);
			
			var volumetric=this.getChildByTag(TAG_VOLUMETRIC);
			//this.addChild(lid66);	
			if(action==ACTION_DO1)
				{
			var move=cc.bezierBy(2, [cc.p(20,150),cc.p(150,150),cc.p(200,200)]);
			var moveback=cc.bezierBy(2, [cc.p(50,50),cc.p(20,20),cc.p(-200,-200)]);
			var seq=cc.sequence(cc.callFunc(function() {
				hand.addlefthand(this, "#hand/hand_left", cc.p(-20,25),0.6);
			},this),move,
			cc.rotateTo(0.35,16.0),
			cc.rotateTo(0.35,0),
			cc.rotateTo(0.35,-16.0),
			cc.rotateTo(0.35,0),
			cc.rotateTo(0.35,16.0),
			cc.rotateTo(0.35,0),
			cc.rotateTo(0.35,-16.0),
			cc.rotateTo(0.35,0),
			moveback,cc.callFunc(function(){
				hand.removehand(this,1,1);
				gg.flow.next()
			}, this));
		this.runAction(seq);
		
				}
			if(action==ACTION_DO2)
			{
				var move=cc.bezierBy(2, [cc.p(20,150),cc.p(150,150),cc.p(200,200)]);
				move1=cc.moveBy(0.5, cc.p(50,0));
				move2=cc.moveBy(0.5, cc.p(-50,0));
				var moveback=cc.bezierBy(2, [cc.p(-50,-50),cc.p(20,20),cc.p(-200,-200)]);
				var seq=cc.sequence(cc.callFunc(function() {
					hand.addlefthand(this, "#hand/hand_left", cc.p(-20,-75),0.6);
					hand.addrighthand(this, "#hand/hand_right", cc.p(25,55),0.6);
				},this),move,
				cc.rotateTo(0.5,90),move1,move2,move1,move2,move1,move2,move1,move2,cc.rotateTo(0.5,0),
			
				moveback,cc.callFunc(function(){
					hand.removehand(this,1,1);
					hand.removehand(this,1,2);
					gg.flow.next()
				}, this));
				this.runAction(seq);

			}
			if(action==ACTION_DO3)
			{
				var move=cc.bezierBy(2, [cc.p(20,80),cc.p(55,180),cc.p(100,270)]);
				move1=cc.moveBy(0.5, cc.p(50,0));
				move2=cc.moveBy(0.5, cc.p(-50,0));
				var moveback=cc.bezierBy(2, [cc.p(0,0),cc.p(20,20),cc.p(-200,-200)]);
				var seq=cc.sequence(cc.callFunc(function() {
					hand.addlefthand(this, "#hand/hand_left", cc.p(-20,-45),0.6);
				//	hand.addrighthand(this, "#hand/hand_right", cc.p(25,55),0.6);
				},this),move,
				cc.rotateTo(1,100),cc.delayTime(3),cc.rotateTo(0.5,0),cc.delayTime(1),

				moveback,cc.callFunc(function(){
					hand.removehand(this,1,1);
					this.setVisible(false);
					//hand.removehand(this,1,2);
					gg.flow.next()
				}, this));
				this.runAction(seq);
               
				var rodnode = this.getParent().getChildByTag(TAG_ROD_NODE2);
				var blb=rodnode.getChildByTag(TAG_ROD1);
				var move1=cc.bezierBy(2,[cc.p(100,150),cc.p(156,100),cc.p(200,60)]);
				//var move1=cc.moveBy(1,cc.p(-136,95));
//				var move3=cc.moveBy(1,cc.p(136,-95));
				var move3=cc.bezierBy(2,[cc.p(-6,200),cc.p(136,115),cc.p(236,-95)]);
				var seq1=cc.sequence(cc.callFunc(function(){
					hand.addrighthand(rodnode, "#hand/hand_right", cc.p(25,35),0.6);
				},this),move1,cc.delayTime(4),move3,cc.callFunc(function(){
					hand.removehand(rodnode, 1, 2);
				//	hand.runAction(cc.fadeOut(0.5));
					rodnode.runAction(cc.fadeOut(0.5));
					blb.runAction(cc.fadeOut(0.1));
				},this));
				rodnode.runAction(seq1);

				var volumetricnode = this.getParent().getChildByTag(TAG_VOLUMETRIC_NODE);
				var volumetric=volumetricnode.getChildByTag(TAG_VOLUMETRIC);

				beaLine = new cc.Sprite("#beaker_line.png");
				beaLine.setOpacity(0);
				var fade=cc.fadeTo(0.5,250);
				beaLine.setScale(0.7, 0.7)
				var rat=cc.rotateTo(0.1,30);
				var scale=cc.scaleTo(1.5,0.9);
				volumetricnode.addChild(beaLine,1);
				var scale1=cc.scaleTo(1.5,0.4);
				var move=cc.moveBy(1.5, volumetric.width * 0.1-5, volumetric.height * 0.1-90)
				beaLine.setPosition(volumetric.width * 0.1-10, volumetric.height * 0.1-85 );
				var spawn=cc.spawn(scale1,cc.moveBy(1.5,cc.p(0,volumetric.height * 0.17)));
				beaLine.runAction(cc.sequence(rat,cc.delayTime(3),fade,cc.spawn(scale,cc.moveBy(1.5,cc.p(10,volumetric.height * 0.17))),spawn,cc.fadeOut(0.5)));
				
				
				var volumetricnode = this.getParent().getChildByTag(TAG_VOLUMETRIC_NODE);
				var volumetric=volumetricnode.getChildByTag(TAG_VOLUMETRIC);

				beaLine1 = volumetricnode.getChildByTag(TAG_BEAKER_LINE1);


			



				beaLine1.runAction(cc.fadeOut(1));
			}
			
		    break;

//

		default:
			break;
		}
	},
	actionDone:function(p){
		switch(p.getTag()){
		case TAG_CALIBRATION:
			var beaker=ll.run.getChildByTag(TAG_BEAKER1);
			beaker.upLine();
			break;
		default:
			break;
		}
		}
});
